<template>
  <div>
    <!-- 经销商收车地址维护 -->
    <TopFilter :list="topFilterList" :cols="3" @resetChange="resetChange" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        :isSelectColumn="false"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        columnsRef="zjPickAddresss"
        :onRowSelectChange="selectChangeHandle"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls" slot-scope="props">
          <multiuse-button size="small" type="primary" @click="addHandle(1)">新 增</multiuse-button>
          <multiuse-button size="small" type="primary" @click="addHandle(2)">导 出</multiuse-button>
        </template>
      </FilterTable>
    </Spin>

    <BaseDialog :visible.sync="issearch" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher @close="dealercloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="emitvisible" :title="'收车信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <emitModel :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="addvisible" :title="'收车信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addModel @close="addcloseHandler" />
    </BaseDialog>
    <!-- <BaseDialog :visible.sync="isvideo" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <videos @close="dealercloseHandler" />
    </BaseDialog> -->
  </div>
</template>
<script>
import { getList, exportList,exporturl } from '@/api/omSale/OrderManagement/PickAddress/index.js';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils';
import ownerSeacher from './ownerSeacher';
import emitModel from './emitModel';
import addModel from './addModel';
import videos from './videos';
export default {
  name: 'TemplateDistribution',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: getList,
      fetchParams: {
        xhrAbort: true
      },
      formData: {},
      emitvisible: false,
      issearch: false,
      addvisible: false,
      exportLoading: false
    };
  },
  components: {
    ownerSeacher,
    emitModel,
    addModel,
    videos
  },
  mixins: [dictionary],
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun(1)}></el-button>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'linkMan',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '地址性质',
          fieldName: 'addressProperty',
          placeholder: '请选择',
          itemList: this.createDictList('6035')
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'status',
          placeholder: '请选择',
          itemList: this.createDictList('1003')
        },

        {
          type: 'SELECT',
          label: '地址类型',
          fieldName: 'addressType',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '地址性质',
          dataIndex: 'addressProperty',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6035'),
          render: p => {
            return <span>{this.createDictText(p.row.addressProperty, '6035')}</span>;
          }
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1003'),
          render: p => {
            return <span>{this.createDictText(p.row.status, '1003')}</span>;
          }
        },

        {
          title: '省份',
          dataIndex: 'provinceId',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createRegionsList(),
          render: p => {
            let arr = this.createRegionsList();
            let str = '';
            arr.map(x => {
              if (x.value == p.row.provinceId) {
                str = x.text;
              }
            });
            return <span>{str}</span>;
          }
        },
        {
          title: '城市',
          dataIndex: 'cityId',
          sorter: true,
          render: p => {
            let arr = this.createcityList(p.row.provinceId);
            let str = '';
            arr.map(x => {
              if (x.value == p.row.cityId) {
                str = x.text;
              }
            });
            return <span>{str}</span>;
          }
        },
        {
          title: '县区',
          dataIndex: 'districtId',
          sorter: true,
          render: p => {
            let arr = this.district(p.row.cityId);
            let str = '';
            arr.map(x => {
              if (x.value == p.row.districtId) {
                str = x.text;
              }
            });
            return <span>{str}</span>;
          }
        },
        {
          title: '结算目的地',
          dataIndex: 'accountAddress',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '详细地址',
          dataIndex: 'address',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '地址编码',
        //   dataIndex: 'dealerAddressNo',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '地址类型',
          dataIndex: 'addressType',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人',
          dataIndex: 'linkMan',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系电话',
          dataIndex: 'linkPhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '修改日期',
          dataIndex: 'updatedAt',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '修改人',
          dataIndex: 'updatedName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    selectChangeHandle(row) {},
    seacherFun() {
      this.issearch = true;
    },
   async addHandle(type) {
      if (type == 1) {
        this.addvisible = true;
      } else {

  let json = Object.assign({}, { CODE: 'CODE_0000031' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }





        // this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        //   confirmButtonText: '下载',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // })
        //   .then(() => {
        //     let json = this.fetchParams;
        //     this.exportLoading = true;
        //     exportList(json)
        //       .then(response => {
        //         exportExcelFile(response.data, '收车地址维护');
        //         this.exportLoading = false;
        //       })
        //       .catch(err => {
        //         console.log(err);
        //       });
        //   })
        //   .catch(() => {
        //     this.$message({
        //       type: 'info',
        //       message: '已取消'
        //     });
        //   });
      }
    },
    changeHandle(params) {
      this.fetchParams.xhrAbort = false;
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data) {
      this.formData = data;
      this.emitvisible = true;
    },
    emitcloseHandler(val) {
      this.emitvisible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    addcloseHandler(val) {
      this.addvisible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    dealercloseHandler(val, data) {
      if (data) {
        let dealerCodes = [];
        data.map(x => {
          dealerCodes.push(x.dealerCode);
        });
        this.topFilterList.find(x => x.fieldName == 'dealerCode').initialValue = dealerCodes.toString();
      }
      this.issearch = false;
    },
    resetChange(val) {
      this.fetchParams = Object.assign({}, this.fetchParams);
    }
  }
};
</script>
